<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px" style="width: 50%">
      <el-form-item label="姓名" prop="name">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-input v-model="form.age"></el-input>
      </el-form-item>
      <el-form-item label="手机" prop="phone">
        <el-input v-model="form.age"></el-input>
      </el-form-item>
      <el-form-item label="验证码" prop="code">
        <el-input v-model="form.age"></el-input>
      </el-form-item>
      <el-button type="primary" @click="submit">提交</el-button>
      <el-button type="primary" @click="submitPart">局部验证</el-button>
      <el-button type="primary" @click="confirm">弹窗确认</el-button>
    </el-form>
  </div>
</template>

<script>
import { formValidate, formValidateField, confirmMsg } from '@/utils'
export default {
  data () {
    return {
      form: {},
      rules: {
        name: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        age: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        phone: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        code: [
          { required: true, message: '必填', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submit () {
      const valid = formValidate(this)
      console.log('valid:', valid)
    },
    submitPart () {
      const valid = formValidateField(this, 'form', ['phone'])
      console.log('valid:', valid)
    },
    async confirm () {
      const message = '是否确认删除'
      const title = '请确认'
      const confirm = await confirmMsg(this, message, title)
      console.log('confirm:', confirm)
    }
  }
}
</script>

<style lang="less" scoped></style>
